package com.easy.core.dbHandle.imp;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;

import com.easy.core.dbHandle.CommonDao;
import com.easy.core.dbHandle.PaginationSupport;

/**
 * <p>Description: </p>
 * <p>CreateDate:@2013-8-23</p>
 * @author zhangj
 */
@SuppressWarnings("unchecked")
public class CommonDaoImp implements CommonDao{

	private BasicDaoImp<Object, Serializable> dao = new BasicDaoImp<Object, Serializable>();
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		dao.setSessionFactory(sessionFactory);
	}

	public <K> K findById(Class<K> clazz, Serializable id) {
		return (K) dao.findById(clazz, id);
	}

	public <K> K findById(String entityName, Serializable id) {
		return (K) dao.findById(entityName, id);
	}

	public <K> List<K> findAll(Class<K> clazz) {
		return dao.findAll(clazz);
	}

	public <K> List<K> findAll(String entityName) {
		return dao.findAll(entityName);
	}

	public <K> List<K> findByCriteria(DetachedCriteria dc) {
		return (List<K>) dao.findByCriteria(dc);
	}

	public <K> List<K> findTopByCriteria(DetachedCriteria dc, int num) {
		return (List<K>) dao.findTopByCriteria(dc, num);
	}

	public Long findCountByCriteria(DetachedCriteria dc) {
		return dao.findCountByCriteria(dc);
	}

	public <K> PaginationSupport<K> findPageByCriteria(DetachedCriteria dc, int pageSize, int startIndex, List<Order> orderList) {
		return (PaginationSupport<K>) dao.findPageByCriteria(dc, pageSize, startIndex, orderList);
	}

	public List<?> findByHQL(String hql, Object... params) {
		return dao.findByHQL(hql, params);
	}

	public Serializable save(Object object) {
		return dao.save(object);
	}

	public Serializable save(String entityName, Object object) {
		return dao.save(entityName, object);
	}

	public void update(Object object) {
		dao.update(object);
	}

	public void update(String entityName, Object object) {
		dao.update(entityName, object);
	}

	public void delete(Object object) {
		dao.delete(object);
	}

	public Session getCurrentSession(boolean allowCreate) {
		return dao.getCurrentSession(allowCreate);
	}

	public SessionFactory getSessionFactory() {
		return dao.getSessionFactory();
	}
	
}
